package com.ikun.consumer;

import com.ikun.domain.User;
import com.ikun.producer.ProducerDemo;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.stereotype.Component;

/**
 * @Classname ConsumerDemo
 * @Description TODO
 * @Date 2025/3/3 21:12
 * @Created by Song zuo gang
 */
@Component
@RocketMQMessageListener(topic = "rocket",consumerGroup = "springBootGroup",consumeThreadMax = 1)
public class ConsumerDemo implements RocketMQListener<User>, RocketMQPushConsumerLifecycleListener {


    @Override
    public void prepareStart(DefaultMQPushConsumer defaultMQPushConsumer) {
        defaultMQPushConsumer.setInstanceName(ProducerDemo.TOPIC);
    }

    @Override
    public void onMessage(User message) {
        long id = Thread.currentThread().getId();
        System.out.println("线程id:"+id+"接收到消息:"+message);
    }

}
